/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package rentcalculator.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author developer
 */
public class DateUtil {
    
    /**
     * d1 must be after d2
     * @param d1
     * @param d2
     * @return 
     */
    public static long days(final Date d1, final Date d2){
        return (long)Math.ceil((d1.getTime() - d2.getTime())/24/1000/60/60)+1;
    }
    
    public static String trunc(final Date date){
        SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd");
        if(date == null ) return null;
        return sdf.format(date);
    }
    
    public static Date genDate(final String date) throws ParseException{
        SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd");
        if(date == null ) return null;
        return new Date(sdf.parse(date).getTime());
    }
}
